import java.util.*;

public class MyStack {
    int []array;
    int top;//记录栈顶位置
    int capacity;//容量
    public MyStack(int x) {
        this.top=-1;
        array=new int[x];//初始化一个x大小的数组
        capacity=x;
    }
    public MyStack() {
        this.top=-1;
        array=new int[4];//默认初始化为4个大小的数组
        capacity=4;

    }
    public boolean empty(){
        return top==-1;
    }
    public boolean full() {
        return top+1==capacity;
    }
    public void push(int x) {
        //判断栈满
        if(full()) {
           array=Arrays.copyOf(array,2*capacity);
            capacity*=2;
        }
        top++;
        array[top]=x;
    }
    //出栈
    public int pop() {
        if(empty()) {
            throw new ArrayEmptyException("栈空");
        }
        return array[top--];
    }
    public int peek() {
        if(empty()) {
            throw new ArrayEmptyException("栈空");
        }
        return array[top];
    }

    public static void main(String[] args) {
        Deque<Integer> deque1=new ArrayDeque<>();
        deque1.offer(1);
        System.out.println(deque1.isEmpty());
        //deque1.poll()
        Stack<Integer> stack=new Stack<>();
       // Deque<Integer> stack1= (Deque<Integer>) new Stack<Integer>();
        Deque<Integer> stack2=new ArrayDeque<>();
        Deque<Integer> deque=new LinkedList<>();
      //  Deque<Integer>deque2=new ArrayList<>();

    }
    public int evalRPN(String[] tokens) {
    //逆波兰表达式求值
        Stack<Integer> stack=new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            if(!tokens[i].equals("+")&&!tokens[i].equals("-")
                    &&!tokens[i].equals("*")&&!tokens[i].equals("/")&&) {
              int n=  Integer.parseInt(tokens[i]);
              stack.push(n);
            }else {
                int a2=stack.pop();
                int a1=stack.pop();
                switch (tokens[i]) {
                    case "+":
                        stack.add(a1+a2);
                        break;
                    case "-":
                        stack.add(a1-a2);
                        break;
                    case "*":
                        stack.add(a1*a2);
                        break;
                    case "/":
                        stack.add(a1/a2);
                        break;
                }
            }
        }
        return stack.pop();
    }
}
class ArrayEmptyException extends RuntimeException{
    public ArrayEmptyException() {
    }

    public ArrayEmptyException(String message) {
        super(message);
    }
}

